import * as service from "@/service";
import IDiscount from "./interface";
const discount: IDiscount = {
  namespaced: true,
  state: {
    discountNav: [],
    discountSuper: [],
    discountList: [],
  },
  actions: {
    async getDiscountNav({ commit }) {
      const result = await service.fetchDiscountNav();
      const action = {
        type: "GET_DISCOUNT_NAV",
        payload: result?.data,
      };
      commit(action);
    },
    async getDiscountSuper({ commit }) {
      const result = await service.fetchDiscountSuper();
      const action = {
        type: "GET_DISCOUNT_SUPER",
        payload: result?.data,
      };
      commit(action);
    },
    async getDiscountList({ commit }, { cId }) {
      const result = await service.fetchDiscountList(cId);
      const action = {
        type: "GET_DISCOUNT_LIST",
        payload: result?.data?.list,
      };
      commit(action);
    },
  },
  mutations: {
    GET_DISCOUNT_NAV(state, action) {
      action.payload.unshift({ id: 0, title: "推荐" });
      state.discountNav = action.payload;
    },
    GET_DISCOUNT_SUPER(state, action) {
      state.discountSuper = action.payload;
    },
    GET_DISCOUNT_LIST(state, action) {
      state.discountList = action.payload;
    },
  },
};

export default discount;
